namespace FubuMVC.Core.Results
{
    public interface ICurrentResult
    {
        IInvocationResult CurrentResult { get; set; }
        IInvocationResult OverrideIfNotAlreadyOverriden(IInvocationResult result);
    }

    public class CurrentRequestResultOverride : ICurrentResult
    {
        public IInvocationResult CurrentResult { get; set; }
        
        public IInvocationResult OverrideIfNotAlreadyOverriden(IInvocationResult result)
        {
            return CurrentResult ?? (CurrentResult = result);
        }
    }

    public static class ResultOverrideExtensions
    {
        public static void RedirectTo(this ICurrentResult overrider, string url)
        {
            overrider.CurrentResult = new RedirectResult(url);
        }
    }
}